<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="com.googlecode.webduff.store.WebdavStore"%>
<%@page import="com.googlecode.webduff.io.URI"%>
<%@page import="com.googlecode.webduff.util.HtmlUtilities"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Hashtable"%>
<%
    WebdavStore theStore = (WebdavStore) request.getAttribute("ListFolder.store");
	URI uri = (URI) request.getAttribute("ListFolder.uri");
	URI requestUri = (URI) request.getAttribute("ListFolder.requestUri");

	Map<String, URI> resourcesToDisplay = new Hashtable<String, URI>();
	
	for(String aResource : theStore.getChildrenNames(uri)) {
		URI anUri = uri.append(aResource);
		resourcesToDisplay.put(anUri.getLastComponent(), anUri);
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	   <title><% out.print("Contents of \"" + uri + "\""); %></title>
	   <style type="text/css" media="screen">
	       @import url("<% out.print(getServletContext().getContextPath()); %>/styles/screen.css");
	   </style>
	   <script type="text/javascript" src="<% out.print(getServletContext().getContextPath()); %>/scripts/prototype.js"></script>
	   <script type="text/javascript" src="<% out.print(getServletContext().getContextPath()); %>/scripts/fastinit.js"></script>
       <script type="text/javascript" src="<% out.print(getServletContext().getContextPath()); %>/scripts/tablekit.js"></script>
	</head>
	<body>
		<div id="head"><div class="pad1"></div>
		    <h1><%
		    URI contextUri = new URI(getServletContext().getContextPath());
		    URI navigatorUri = requestUri.subsetFromBegin(contextUri.size());
		    URI linkedNavigatorUri = new URI("/");
		    for(int i = 0 ; i < navigatorUri.size() ; i++) {
		    	URI a = contextUri.append(navigatorUri.subsetToEnd(i + 1));
		    	linkedNavigatorUri = linkedNavigatorUri.append(HtmlUtilities.getHref(navigatorUri.getNthComponent(i), a));
		    }
		    out.print("Contents of " + linkedNavigatorUri);
		    %></h1>
		</div>
		<div id="content"><div class="pad2"></div>
		    <table class="sortable resizable" width="100%">
				<thead>
				    <tr>
				        <th>Filename</th>
				        <th class="number">Size</th>
				        <th>Type</th>
				        <th>Creation Date</th>
				        <th>Last Modified Date</th>
				    </tr>
				</thead>
		        <tbody>
		            <%
	                    for (String name : resourcesToDisplay.keySet()) {
	                    	URI anUri = resourcesToDisplay.get(name);
	                        out.println("<tr>");
	                            // filename
		                        out.println("<td>");
	                            out.println(HtmlUtilities.getImage(contextUri.append(new URI(HtmlUtilities.getImageForMimeType(theStore.getMimeType(anUri))))));
		                        out.println(HtmlUtilities.getHref(name, requestUri.append(name).toString()));
		                        out.println("</td>");
		                        
		                        // size
		                        out.println("<td>");
		                        out.println(theStore.getResourceLength(anUri));
	                            out.println("</td>");
	                            
	                            // type
	                            out.println("<td>");
	                            out.println(theStore.getMimeType(anUri));
	                            out.println("</td>");
	                            
	                            // creation date
	                            out.println("<td align=\"center\">");
	                            out.println(theStore.getCreationDate(anUri));
	                            out.println("</td>");
	                            
	                            // last modified
	                            out.println("<td align=\"center\">");
	                            out.println(theStore.getLastModified(anUri));
                                out.println("</td>");
	                        out.println("</tr>");
	                    }
	                %>
                </tbody>
		    </table>
		<div class="pad2"></div></div>
		<div id="foot">powered by WebDuff &amp; <% out.print(getServletInfo()); %></div>
	</body>
</html>